package com.service.scheduling.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.dao.enums.HashRateOrderEnums;
import com.service.dao.enums.LockProductEnums;
import com.service.dao.mapper.OrderProductLockComboMapper;
import com.service.dao.model.OrderProductLockCombo;
import com.service.scheduling.service.OrderProductLockComboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Slf4j
@Service("orderProductLockComboService")
public class OrderProductLockComboServiceImpl extends ServiceImpl<OrderProductLockComboMapper, OrderProductLockCombo> implements
		OrderProductLockComboService {

	/**
	 * @param orderStatus
	 * @Description: 获取结束时间大于当前时间的订单
	 * @Author: ty
	 * @Date: 2021/5/11 14:14
	 * @param: [orderStatus]
	 * @return: java.util.List<com.service.dao.model.OrderProductLockCombo>
	 */
	@Override
	public List<OrderProductLockCombo> listOrderByStatus(Integer orderStatus) {
		return baseMapper.listOrderByStatus(orderStatus);
	}

	/**
	 * @param endLockComboList
	 * @Description: 结束订单
	 * @Author: ty
	 * @Date: 2021/5/11 15:04
	 * @param: [lockComboList]
	 * @return: void
	 */
	@Override
	public void finishLockOrderList(List<OrderProductLockCombo> endLockComboList) {
		if(!ObjectUtils.isEmpty(endLockComboList)){
			endLockComboList.parallelStream().forEach(item->{
				item.setOrderStatus(HashRateOrderEnums.Status.complete.getCode());
				item.setLockStatus(LockProductEnums.LockStatus.EXPIRED.getCode());
			});
		}
		updateBatchById(endLockComboList);
	}
}
